package com.net.url02;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * 流的操作
 *
 * @author jiangbang
 * @date 2016/7/22
 */
public class UrlDemo02 {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http://www.baidu.com"); //默认资源
        //获取资源 网络流
//        InputStream is = url.openStream();
//        byte[] flush = new byte[1024];
//        int len = 0;
//        while(-1!=(len=is.read(flush))){
//            System.out.println(new String(flush,0,len));
//        }
//        is.close();

        //获取资源 通过转换流来做
        BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(),"utf-8"));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("C:\\Users\\Administrator\\Desktop\\学习文档\\PDF\\1.txt")));
        String msg = null;
        while ((msg = br.readLine())!=null){
            bw.append(msg);
            bw.newLine();
        }
        br.close();
        bw.flush();
        bw.close();
    }
}
